home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: sizeof() question >>> :)
- Date: Thu, 18 Apr 1996 16:16:01 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4l5pqj$c8m@news.halcyon.com>
- References: <1996Apr12.061927@topaz> <31714828.1574068@news.linex.com> <4l0dcr$14t0@darwin.nbnet.nb.ca> <danpop.829678939@news.cern.ch> <4l4fik$1a8_005@donstarr.best.com>
- NNTP-Posting-Host: blv-pm3-ip12.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- super@donstarr.org (Don Starr) wrote:
-
- >In article <danpop.829678939@news.cern.ch>,
- > danpop@mail.cern.ch (Dan Pop) wrote:
- >*>
- >*> If you allocate the space for the array you can call one of the memory
- >*> routines which return the size of the allocation.
- >*> Dave Gaudet via Rick Bruce
- >*
- >*There is no such "routine" in the C language.
- >*
- >*Dan
-
- >Technically, there is no such _any_ routine in the C language. The language
- >doesn't define any functions - "standard" libraries do.
-
- >As to the original question, if you know how your heap is structured (from
- >the source to your malloc(), new, or whatever), you can get the size of any
- >allocation from it.
-
- >Don
-
- You can? Post some code.
- Even when there's some support behind it, e.g. the GlobalSize()
- function in MS Windows, the size returned may be padded larger than
- the amount you've requested. You can guess how big the memory is
- you're using.
- BTW, some memory management routines add on extra bytes, even beyond
- the padding, to track allocations, detect overwrites, etc. and these
- fields would also enter into your hypothetical allocated_sizeof(), but
- maybe only if _DEBUG is defined. However, you don't dare overwite
- these fields.
- I think the wisest advise is to track the size yourself when you
- allocate, pass array dims yourself to functions, etc.
- --Norm
-
-